package com.manage.platform.controller;

import com.manage.platform.dto.OrganizeDto;
import com.manage.platform.dto.OrganizeMemberDto;
import com.manage.platform.dto.OrganizeTreeDto;
import com.manage.platform.dto.query.OrganizeMemberQuery;
import com.manage.platform.dto.query.OrganizeMemberTwoQuery;
import com.manage.platform.service.impl.OrganizeServiceImpl;
import com.manage.platform.service.impl.UserServiceImpl;
import com.manage.platform.utils.R;
import com.manage.platform.utils.RPage;
import com.manage.platform.vo.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * YWD
 * 2025/9/24
 */
@AllArgsConstructor
@RestController
@RequestMapping("/organize")
@Tag(name = "学校基础信息-组织架构")
public class OrganizeController {

    private final OrganizeServiceImpl organizeServiceImpl;
    private final UserServiceImpl userServiceImpl;

    @PostMapping("/getOrganizeTree")
    @Operation(summary = "1.查询组织列表(树形)")
    public R<List<OrganizeTreeVo>> getOrganizeTree(@RequestBody OrganizeTreeDto dto) {
        return R.ok(organizeServiceImpl.getOrganizeTree(dto));
    }

    @PostMapping("/getOrganizeMemberPage")
    @Operation(summary = "2.查询组织关联员工列表(分页)")
    public R<RPage<List<OrganizeMemberVo>>> getOrganizeMemberPage(@RequestBody OrganizeMemberQuery query) {
        return R.ok(organizeServiceImpl.getOrganizeMemberPage(query));
    }

    @PutMapping("/updateOrganizeMember")
    @Operation(summary = "3.修改组织关联员工列表")
    public R<Boolean> updateOrganizeMember(@RequestBody List<OrganizeMemberVo> dto) {
        return R.ok(organizeServiceImpl.updateOrganizeMember(dto));
    }

    @PutMapping("/saveOrganizeMember")
    @Operation(summary = "4.新增组织关联员工")
    public R<Boolean> saveOrganizeMember(@RequestBody OrganizeMemberDto dto) {
        return R.ok(organizeServiceImpl.saveOrganizeMember(dto));
    }

    @PutMapping("/deleteOrganizeMember")
    @Operation(summary = "5.删除组织关联员工")
    public R<Boolean> deleteOrganizeMember(@RequestBody OrganizeMemberDto dto) {
        return R.ok(organizeServiceImpl.deleteOrganizeMember(dto));
    }

    @PostMapping("/saveOrganize")
    @Operation(summary = "6.添加组织")
    public R<Boolean> saveOrganize(@RequestBody OrganizeDto dto) {
        return R.ok(organizeServiceImpl.saveOrganize(dto));
    }

    @GetMapping("/getOrganizeMemberList")
    @Operation(summary = "7.人员列表(成员/负责人)(筛选项)")
    public R<List<OrganizeMemberPartVo>> getOrganizeMemberList(@Schema(description = "人员姓名")
                                                               @RequestParam(value = "realName", required = false) String realName) {
        return R.ok(userServiceImpl.getUserList(realName));
    }

    @PostMapping("/getOrganizeMemberTwoPage")
    @Operation(summary = "8.查询组织关联员工列表分页(成员配置列表回显)(分页)")
    public R<RPage<List<OrganizeMemberVo>>> getOrganizeMemberTwoPage(@RequestBody OrganizeMemberTwoQuery query) {
        return R.ok(organizeServiceImpl.getOrganizeMemberTwoPage(query));
    }

    @GetMapping("/getOrganizeHeadUser")
    @Operation(summary = "9.主要负责人(信息回显)")
    public R<OrganizeHeadUserVo> getOrganizeHeadUser(@Schema(description = "主要负责人ID")
                                                     @RequestParam(value = "headId") Long headId) {
        return R.ok(organizeServiceImpl.getOrganizeHeadUser(headId));
    }

    @PutMapping("/updateOrganize")
    @Operation(summary = "10.修改组织")
    public R<Boolean> updateOrganize(@RequestBody OrganizeDto dto) {
        return R.ok(organizeServiceImpl.updateOrganize(dto));
    }

    @DeleteMapping("/deleteOrganize/{id}")
    @Operation(summary = "11.删除组织")
    public R<Boolean> deleteOrganize(@Schema(description = "组织ID") @PathVariable("id") Long id) {
        return R.ok(organizeServiceImpl.deleteOrganize(id));
    }

    @GetMapping("/getOrganizeDetails/{id}")
    @Operation(summary = "12.查询组织详情")
    public R<OrganizeDetailsVo> getOrganizeDetails(@Schema(description = "组织ID") @PathVariable("id") Long id) {
        return R.ok(organizeServiceImpl.getOrganizeDetails(id));
    }


    //筛选项========================================================================================================
    @GetMapping("/getOrganizePartList")
    @Operation(summary = "13.组织列表(筛选项)")
    public R<List<CommonVo>> getOrganizePartList(@Schema(description = "组织名称")
                                                 @RequestParam(value = "name", required = false) String name,
                                                 @Schema(description = "组织类型(COLLEGE:学院,DEPARTMENT:部门)")
                                                 @RequestParam(value = "type", required = false) String type) {
        return R.ok(organizeServiceImpl.getOrganizePartList(name, type));
    }

    @GetMapping("/getCollegeList")
    @Operation(summary = "14.学院列表(筛选项)")
    public R<List<CommonVo>> getCollegeList(@Schema(description = "学院名称")
                                            @RequestParam(value = "name", required = false) String name) {
        return R.ok(organizeServiceImpl.getCollegeList(name));
    }

    @GetMapping("/getDepartmentList")
    @Operation(summary = "15.部门列表(筛选项)")
    public R<List<CommonVo>> getDepartmentList(@Schema(description = "部门名称")
                                               @RequestParam(value = "name", required = false) String name) {
        return R.ok(organizeServiceImpl.getDepartmentList(name));
    }


}
